import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const routes = [
  {
    path: '/login',
    component: () => import('@/views/login.vue'),
    hidden: true,
  },
  {
    path: '/app',
    name: 'app',
    component: () => import('@/layout/index.vue'),
    children: [
      {
        path: 'coupon',
        name: 'coupon',
        component: () => import('@/views/coupon.vue'),
        meta: {
          index: '1',
          title: '券码管理',
          icon: 'el-icon-present',
        },
        children: [],
      },
      {
        path: 'order',
        name: 'order',
        component: () => import('@/views/order.vue'),
        meta: {
          index: '2',
          title: '订单管理',
          icon: 'el-icon-bank-card',
        },
        children: [],
      },
      {
        path: 'notify',
        name: 'notify',
        component: () => import('@/views/notify.vue'),
        meta: {
          index: '3',
          title: '通知消息',
          icon: 'el-icon-message',
        },
        children: [],
      },
    ],
  },
  {
    path: '/:pathMatch(.*)*',
    redirect: '/app/coupon',
  },
];

// 防止连续点击多次路由报错
const routerPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch((err) => err);
};

const router = new Router({
  mode: 'history',
  base: `${process.env.BASE_URL}`,
  routes,
});

export default router;
